package org.servlet;

import org.domain.Order;
import org.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SubmitServlet extends HttpServlet {
    private static final String VIEW_ORDER = "/WEB-INF/order/ViewOrder.jsp";
    private OrderService orderService;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        orderService = new OrderService();
        int id = Integer.parseInt(request.getParameter("id"));
        Order order = orderService.getOrder(id);
        HttpSession session = request.getSession();
        session.setAttribute("order", order);
        request.getRequestDispatcher(VIEW_ORDER).forward(request, response);
    }
}
